#include "pthread_demo2.h"
#include <stdio.h>
#define PTHREAD_NUM 2000
int sum = 0;
static pthread_mutex_t pthread_mutex = PTHREAD_MUTEX_INITIALIZER;
static void* func(void* args)
{
    pthread_mutex_lock(&pthread_mutex);
    sum++;
    pthread_mutex_unlock(&pthread_mutex);
    pthread_exit(NULL);
}
int main(void)
{
    pthread_t pthread_arr[PTHREAD_NUM];
    for (int i = 0; i < PTHREAD_NUM; i++)
    {
        pthread_create(&pthread_arr[i],NULL,func,NULL);
    }
    for (int i = 0; i < PTHREAD_NUM; i++)
    {
        pthread_join(pthread_arr[i],NULL);
    }
    printf("sum=%d\n",sum);
    return 0;
}